﻿
using Newtonsoft.Json;
using RTW.OA.Areas.Meeting.Servers;
using RTW.OA.Models;
using RTW.Utils.Utils;
using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace RTW.OA.Areas.Meeting.Controllers
{
    public class MeetingSummaryController : Controller
    {
        private MeetingSummaryServers meetingsummaryServers;

        public MeetingSummaryController()
        {
            meetingsummaryServers = new MeetingSummaryServers();
        }


        // GET: Meeting/MeetingSummary
        public ActionResult Index()
        {
            ViewBag.M_ROOMData = meetingsummaryServers.GetM_ROOM(1);
            ViewBag.M_ROOMDataJS = JsonConvert.SerializeObject(meetingsummaryServers.GetM_ROOM(0));

            return View();
        }

        // GET: Meeting/MeetingSummary/Edit/5
        public ActionResult Edit(int? id)
        {
            var model = new meeting();
            if (id != null)
            {
                ViewBag.Title = "编辑会议表";
                model = GetModel(id.Value.ToString());
            }
            else
            {
                ViewBag.Title = "新建会议表";
            }
            return View(model);
        }

        // POST: Meeting/MeetingSummary/Edit/5
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(int? id, meeting model)
        {
            try
            {
                if (id == null || id == 0)
                {
                    meetingsummaryServers.Add(model);
                    ViewBag.msg = "新增会议表信息成功！";
                    model = new meeting();

                }
                else
                {
                    meeting modelM = meetingsummaryServers.GetModelById(id.ToString());
                    modelM.SUMMARY = model.SUMMARY;
                    modelM.READ_PEOPLE_ID = model.READ_PEOPLE_ID;
                    modelM.ATTACHMENT_ID1 = model.ATTACHMENT_ID1;
                    modelM.ATTACHMENT_NAME1 = model.ATTACHMENT_NAME1;
                    modelM.M_FACT_ATTENDEE = model.M_FACT_ATTENDEE;
                    modelM.APPROVE_NAME = model.APPROVE_NAME;
                    meetingsummaryServers.Update(modelM);
                    ViewBag.msg = "修改会议表信息成功！";
                    model = modelM;

                }
            }
            catch
            {
                ViewBag.msg = "提交出现错误！";
            }

            return View(model);
        }
        public ActionResult MeetingSummaryDetails(int? id)
        {
            var model = new meeting();
            model = GetModel(id.Value.ToString());
            return View(model);
        }

        // GET: Meeting/MeetingSummary/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                meetingsummaryServers.Del(id.ToString());
                ViewBag.msg = "删除会议表信息成功！";
            }
            return Content("");
        }


        #region //GetData
        public string GetTableJsonResult( string M_NAME, string M_PROPOSER, string M_START, string M_END, string M_ROOM, string SUMMARY)
        {
            var list = meetingsummaryServers.GetData(M_NAME, M_PROPOSER, M_START, M_END, M_ROOM, SUMMARY);
            return JsonConvert.SerializeObject(list);
        }

        public meeting GetModel(string id)
        {
            var model = meetingsummaryServers.GetModelById(id);
            return model;
        }

        #endregion //GetData
    }
}